<template>
	<view class="inner_page">
		<home-barTittle :title="title" :showBack="true"></home-barTittle>
		<view class="mphtml pd16_15 mb16 cl-main">
			<mp-html :content="info.activityInfo"/>
		</view>
		<view class="activity-info-bottom pd20_15">
			<view class="ft18 cl-main ftw600">活动主题：{{info.activityName}}</view>
			<view class="ft18 cl-main ftw600">活动费用：{{info.activityCost}}</view>
			<view class="ft18 cl-main ftw600">活动时间：{{info.activityTime}}</view>
			<view class="ft18 cl-main ftw600">活动地址：{{info.activityAddress}}</view>
			<button class="button-signin" style="margin-top: 35rpx; font-size: 40upx; color: #000000; height: 80rpx; line-height: 80rpx;"
				@click="signUp()"
				 withCredentials="true">点击报名</button>
		</view>
		
		
		<dialog-login v-if="showLogin" @loginYes="loginYes" @closed="showLogin = false"></dialog-login>
		
	</view>
</template>

<script>

import infoVue from './info.vue';
// import mapTencent from '@/components/map/map-tencent.vue';
// import mpHtml from 'mp-html/dist/components/mp-html/mp-html'
// import zaudio from 'uniapp-zaudio/zaudio'

export default {
	
	data(){
		return {
			title:"报名须知",
			
			processedRichText:'',
			
			isLogin:false,
			showLogin:false,
			showVideo:false,
			autoplay:false,
			playbtn:true,
			selectIndex:0,
			tabs:['目录','详情'],
			nextStep:'',
			datasa:[],
			dataconfig:[],
			id:'',
			mid:0,
			info:[],
			userPaidStatus:'',
			dda:'',
			price:'',
			banners:[],
			isplaytext:'已经购买',
			audioAction: {
				method: 'pause'
			}
		}
	},
	computed: {
		
	},
	onLoad(option){
		// this.dda=uni.createVideoContext('myVideo')
		if(option.activityId){
			this.id=option.activityId
		}
	},
	onShow() {
		// if(uni.getStorageSync("userinfo").token){
		// 	this.isLogin = true
		// 	this.showLogin = false
		// }
		
		this.getInfo(this.id);
	},
	onHide() {
		this.dda.pause()
	},
	onShareAppMessage(e){
		
	},
	onShareTimeline(e){
		
	},
	methods:{
		signUp() {
			//判断登录状态
			
			uni.setStorage({//缓存配置信息
				key: 'buydata',  
				data: this.info
			})
			uni.navigateTo({
				url:"/sub_pages/activity/buy"
			})
		},
		getInfo(id) {
			console.log("getInfo")
			uni.showLoading({
				title: '加载中'
			});
			// let data = {};
			if(uni.getStorageSync("userinfo").token){
				// data.token=uni.getStorageSync("userinfo").token
				this.isLogin = true
			}
			uni.request({
				url: this.configs.webUrl+'/miniapp/activity/'+id ,
				// data: data,
				success: data => {
						uni.hideLoading();
						this.info=[];
						this.info=data.data.data
						// console.log('this.info')
						// console.log(this.info)
						this.processedRichText = this.info.activityInfo
						// console.log("richText")
						// console.log(this.processedRichText)
						
						uni.setNavigationBarTitle({
							title: this.info.activityName
						});
				},
				fail: (data, code) => {
					uni.hideLoading();
				}
			});
		},
		
		/**
		 * 判断景点是否免费
		 * @param {boolean} userPaidStatus - 是否付费过任意景点（关键全局状态）
		 * @param {boolean} areaChargeStatus - 景区状态：'收费'/'免费'
		 * @param {boolean} videoChargeStatus - 景点状态：'收费'/'免费'
		 * @returns {boolean} - true=免费 / false=收费
		 */
		isVideoFree(userPaidStatus, areaChargeStatus, videoChargeStatus) {
			console.log(userPaidStatus, areaChargeStatus, videoChargeStatus)
		  // 规则1：付费过任意景点 → 所有景点免费
		  if (userPaidStatus) return true;
		  
		  // 规则2：景区整体免费 → 所有景点免费
		  if (areaChargeStatus === false) return true;
		  
		  // 规则3：以上均不满足时，检查景点自身状态
		  return videoChargeStatus === false;
		},
		buys(value){
			let dataa = {};
			this.info.priced=value.price
			this.info.vippriced=value.vipprice
			this.info.pricedbuy=this.info.price
			if(uni.getStorageSync("userinfo").apiToken){
				if(this.info.isvip>1){
					this.info.pricedbuy=value.vipprice
				}
			}
			console.log(value)
			
			uni.setStorage({//缓存配置信息
				key: 'buydata',  
				data: this.info
			})
			uni.navigateTo({
				url:'/sub_pages/scenicArea/buy?id='+this.id+'&mid='+value.id
			})	
		},
		timeupdate(event){
				let _this=this;
				let currentTime = event.detail.currentTime 
				if(currentTime>this.info.mrseek && this.info.isplay==0){
					 //dda.exitFullScreen()
					 this.dda.seek(this.info.mrseek)
					 this.dda.pause()
					 this.dda.stop()
					 uni.showModal({
						title: '温馨提示',
						content: '没权限观看当前视频',
						showCancel: false,
						confirmText: "确定",
						success: function (res) {
							if (res.confirm) {
								
							} else if (res.cancel) {
								
							}
						}
					 });
				}
		},
		
		// 判断当前用户是否已经购买了当前景区的视频权限（购买任一视频权限，均开放当前景区内的所有视频权限）
		checkPaid(scenicId){
			var userinfo = uni.getStorageSync("userinfo");
			uni.request({
				url: this.configs.webUrl+'/api/scenicArea/checkPaid',
				data: {
					userId: userinfo.id,
					scenicAreaId: scenicId
				},
				method:'POST',
				
				success: data => {
					console.log("checkPaid");
					this.userPaidStatus = data.data.data;
					console.log(this.userPaidStatus);
					
					// this.checkShowVideo();
				},
				fail: (data, code) => {
				}
			});
		},
		checkShowVideo(){
			// 1.景区免费
			// 2.景区收费&景点免费
			// 3.景区收费&已付费
			this.showVideo = true;
		},
		
		contactAct(){
			if(this.isLogin == false){
				this.showLogin = true;
				this.nextStep = 'contact';
			}else{
				uni.navigateTo({
					url:'/pages/client/vipcard/adviser'
				})
			}
		},
		vipcard(){
			uni.navigateTo({
				url:'/pages/client/vipcard/index'
			})
		},
		detail(id,mid){
			uni.navigateTo({
				url:'/sub_pages/scenicArea/detail?id='+id+'&mid='+mid
			})
			
			// console.log("收费："+this.info.chargeStatus)
			// if(this.info.chargeStatus & !this.userPaidStatus){
			// 	uni.navigateTo({
			// 		url:'/sub_pages/scenicArea/buy?id='+id+'&mid='+mid
			// 	})
			// }else{
			// 	uni.navigateTo({
			// 		url:'/sub_pages/scenicArea/detail?id='+id+'&mid='+mid
			// 	})
			// }
			
		},
		buyAct(){
			if(this.price*1==0){
				uni.showToast({ title: '免费视频不需要购买',icon:"none" });
						return false; 
					}
					if(this.isLogin == false){
						this.showLogin = true;
						this.nextStep = 'buy';
					}else{
						uni.setStorage({//缓存配置信息
							key: 'buydata',  
							data: this.info
						})
						uni.navigateTo({
							url:'/sub_pages/scenicArea/buy?id='+this.id
						})
					}
				},
			loginYes(){
				if(this.nextStep == 'buy'){
					uni.navigateTo({
						url:'/sub_pages/scenicArea/buy'
					})
				}else{
					uni.navigateTo({
						url:'/pages/client/vipcard/adviser'
					})
				}
			},
			changeIndex(index){
				this.selectIndex = index;
			}
		}
	}
</script>

<style>

	/* 富文本自动换行 */
	.mphtml{
		white-space: pre-wrap; /* CSS3 */
		word-wrap: break-word; /* Internet Explorer 5.5+ */
		padding-bottom: 200px;
	}
	/* 底部悬浮框 */
	.activity-info-bottom{
		width: 100%;
		background: #fdf6e3;
		border-radius: 40rpx 40rpx 0rpx 0rpx;
		position: fixed;
		bottom: 0;
		margin-top: 20rpx;
	}
	/* 报名按钮 */
	.button-signin{
		color: #FFFFFF;
		font-size: 34rpx;
		width: 470rpx;
		height: 100rpx;
		background: linear-gradient(-90deg, rgba(75, 196, 93, 1), rgba(188, 226, 158, 1));
		box-shadow: 0rpx 0rpx 13rpx 0rpx rgba(164, 217, 228, 0.2);
		border-radius: 50rpx;
		line-height: 100rpx;
		text-align: center;
		margin-left: auto;
		margin-right: auto;
		margin-top: 100rpx;
	}
	
	.activityInfo{
	
	}
</style>